
package com.timber.util;
import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import javax.swing.SwingConstants;
import javax.swing.JTable;

public class SLDateTimeRenderer extends DefaultSLObjectRenderer
{
  protected static SimpleDateFormat sdf = new SimpleDateFormat( "dd-MMM-yy HH:mm:ss z", Locale.ENGLISH );

  private static TimeZone tz = Util.getLocationTZ();
  private static Calendar gcl = new GregorianCalendar();

  public SLDateTimeRenderer()
  {
    super();

    sdf.setTimeZone( tz );
    m_format = sdf;

    setHorizontalAlignment( SwingConstants.RIGHT );
  }

  public SLDateTimeRenderer( int alignment )
  {
    this();
    setHorizontalAlignment( SwingConstants.RIGHT );
  }

  public Component getTableCellRendererComponent( JTable  t,
						  Object  o,
						  boolean sel,
						  boolean foc,
						  int     row,
						  int     col )
  {
    if( o != null && o instanceof java.util.Date )
    {
      gcl.setTime( ( java.util.Date )o );
      int offset = gcl.get( GregorianCalendar.ZONE_OFFSET ) + gcl.get( GregorianCalendar.DST_OFFSET );
      o = new java.util.Date( ( ( java.util.Date )o ).getTime() + offset );
    }

    return super.getTableCellRendererComponent( t, o, sel, foc, row, col );
  }
}
